package com.meida.module.arc.provider.controller;

import com.meida.common.utils.ApiAssert;
import com.meida.common.utils.DateUtil;
import com.meida.module.arc.provider.log.annotation.LogAspect;
import com.meida.module.arc.provider.log.enums.LogOptTypeEnum;
import com.meida.module.arc.provider.log.enums.LogTypeEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.meida.common.mybatis.model.*;

import java.util.Date;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RestController;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.arc.client.entity.ArcStoreRecord;
import com.meida.module.arc.provider.service.ArcStoreRecordService;


/**
 * 出入库记录控制器
 *
 * @author flyme
 * @date 2022-01-03
 */
@RestController
@RequestMapping("/arc/store/record/")
public class ArcStoreRecordController extends BaseController<ArcStoreRecordService, ArcStoreRecord>  {

    @ApiOperation(value = "出入库记录-分页列表", notes = "出入库记录分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "出入库记录-列表", notes = "出入库记录列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "出入库记录-添加", notes = "添加出入库记录")
    @PostMapping(value = "save")
    @LogAspect(logType = LogTypeEnum.LOG_OPERATE,optType = LogOptTypeEnum.STORERECORD,optObj="添加出入库记录")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "出入库记录-更新", notes = "更新出入库记录")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "出入库记录-删除", notes = "删除出入库记录")
    @PostMapping(value = "remove")
    @LogAspect(logType = LogTypeEnum.LOG_OPERATE,optType = LogOptTypeEnum.STORERECORD,optObj="删除出入库记录")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "出入库记录-详情", notes = "出入库记录详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @GetMapping(value = "export")
    @LogAspect(logType = LogTypeEnum.LOG_OPERATE,optType = LogOptTypeEnum.STORERECORD,optObj="导出出入库记录")
    public void export(@RequestParam(required = false) Map params, HttpServletRequest request, HttpServletResponse response) {
        request.setAttribute("reqParam",params);
        ApiAssert.isNotEmpty("全宗id不能为空",params.get("qzId"));
        params.put("columns","[\n" +
                "    {\n" +
                "        \"key\": \"arcType\",\n" +
                "        \"name\": \"档案类型\"\n" +
                "    },{\n" +
                "        \"key\": \"unitId\",\n" +
                "        \"name\": \"所属部门\",\n" +
                "        \"dict\": \"unitId\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"arcNum\",\n" +
                "        \"name\": \"档号\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"handlerPerson\",\n" +
                "        \"name\": \"经手人\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"operatorName\",\n" +
                "        \"name\": \"操作员\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"operatorTime\",\n" +
                "        \"name\": \"操作时间\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"operatorType\",\n" +
                "        \"name\": \"操作类型\",\n" +
                "        \"dict\": \"operatorTypeDict\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"reason\",\n" +
                "        \"name\": \"出入库原因\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"key\": \"remark\",\n" +
                "        \"name\": \"备注\"\n" +
                "    }\n" +
                "]");
        bizService.export(null,params, request, response, "出入库记录"+ DateUtil.date2Str(new Date(),"yyyyMMddHHmmss"), "出入库记录","arcStoreRecordExportHandler");
    }

}
